﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="AddGroup.aspx.cs" Inherits="background.Manager.Enterprise.Album.AddGroup" %>

<!DOCTYPE html>
<% 
    if(string.IsNullOrEmpty(Request["actionType"])) { Response.Write("缺少actionType参数"); return; }
    if(!new Regex("^(add|update)$").IsMatch(Request["actionType"])) { Response.Write("actionType参数：只能是add或update"); return; }
    if(Request["actionType"].ToString()=="update") {
        if(string.IsNullOrEmpty(Request["id"])) { Response.Write("缺少id参数"); return; }
        if(!new Regex("^\\d+$").IsMatch(Request["id"])) { Response.Write("id参数错误"); return; }
    }
%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>添加相册</title>
    <link href="../../Styles/index.css" rel="stylesheet" />
    <script src="../../Scripts/jquery-1.8.2.min.js"></script>
    <script src="../../Scripts/layer/layer.js"></script>

</head>
<body>
    <div class="top">
        <strong>相册编辑</strong>
        <span style="float: right"><a href="javascript:history.back();">
            <img src="../../Images/bak.png" />后退</a></span>
    </div>
    <div class="main">
        <!--表单提交-->
        <div>
            <table border="0" cellpadding="0" cellspacing="0" class="table">
                <tr>
                    <th>相册名字</th>
                    <td>
                        <input type="text" id="album_name" class="text" value="" /><i>*</i></td>
                </tr>
                <tr>
                    <th style="vertical-align: top">相册介绍</th>
                    <td>
                        <textarea class="text" id="album_remark" maxlength="255" style="width: 276px; height: 60px"></textarea><i>最多255个字符</i></td>
                </tr>
                <tr>
                    <th>排序</th>
                    <td>
                        <input type="text" id="album_order" class="text" value="0" /><i>数字越小排名越靠前</i></td>
                </tr>
                <tr>
                    <th>查看权限</th>
                    <td>
                        <label>
                            <input type="radio" name="ablum_state" value="1" checked="checked" />公开</label>
                        <label>
                            <input type="radio" name="ablum_state" value="0" />不公开</label>
                    </td>
                </tr>
                <tr>
                    <th>图片尺寸</th>
                    <td>
                        <input type="text" class="text" id="picture_width" value="" style="width: 112px;" placeholder="宽" />PX
                    &nbsp;&nbsp;
                    <input type="text" class="text" id="picture_height" value="" style="width: 113px;" placeholder="高" />PX
                    &nbsp;<i>建议上传图片尺寸（宽-高）</i>
                    </td>
                </tr>
                <tr>
                    <td></td>
                    <td>
                        <input type="button" class="sbtn" value="保存" onclick="p.addAblum()" /></td>
                </tr>
            </table>
        </div>
    </div>
    <script type="text/javascript">
        var p = {
            addAblum: function () {
                
                var album_name = $("#album_name"),
                    album_remark = $("#album_remark"),
                    album_order = $("#album_order"),
                    ablum_state = $("input[name=ablum_state]:checked").val(),
                    width = $("#picture_width"),
                    height = $("#picture_height");
                if (album_name.val().length == 0) { layer.msg("请输入相册名字"); album_name.focus(); return; }
                if (!/^\d+$/.test(album_order.val())) { layer.msg("排序只能输入数字"); album_order.focus(); return; }
                if (width.val().length > 0) {
                    if (!/^\d+$/.test(width.val())) { layer.msg("图片宽只能是数字"); width.focus(); return; }
                }
                if (height.val().length > 0) {
                    if (!/^\d+$/.test(height.val())) { layer.msg("图片高只能是数字"); height.focus(); return; }
                }
                var data = {
                    action: "<%=Request["actionType"]%>",
                    name: album_name.val(),
                    remark: album_remark.val(),
                    order: album_order.val(),
                    state: ablum_state,
                    imagesize: width.val() + "," + height.val()
                }
                if ('<%=Request["actionType"]%>' == 'update') {
                    data["id"] = '<%=Request["id"]%>';
                }
                $.post("Action/albumGroup.ashx", data, function (ret) {
                    if (ret) {
                        layer.msg("恭喜您保存成功", { icon: 1, time: 2000 }, function () { window.location.href = "AlbumList.aspx"; })
                    } else {
                        layer.msg("对不起保存失败", { icon: 2, time: 2000 })
                    }
                })
            },
            loadData: function () {
                $.getJSON("Action/albumGroup.ashx", { action: "getInfo", id: '<%=Request["id"]%>' }, function (resultJson) {
                    var json = resultJson[0];
                    $("#album_name").val(json.Name);
                    $("#album_remark").val(json.Remark);
                    $("#album_order").val(json.Order);
                    $("input[name=ablum_state][value=" + json.State + "]").attr("selected", "selected");
                    var wh = json.ImageSize.split(',');
                    $("#picture_width").val(wh[0]);
                    $("#picture_height").val(wh[1]);
                })
            }
        }
        <%=string.IsNullOrEmpty(Request["id"])?"":"p.loadData();"%>
    </script>
    <!--#include file='../../Include/footer.html'-->
</body>
</html>
